import functools

from flask import session, current_app, jsonify,g

from infos.utils.response_code import RET


def index_class(index):
    if index == 1:
        return 'first'
    elif index == 2:
        return 'second'
    elif index == 3:
        return 'third'
    else:
        return ''

# 校验用户ID
def login_in(f):
    @functools.wraps(f)
    def inner(*args,**kwargs):
        user_id = session.get('user_id')
        user = None
        if user_id:
            try:
                from infos.models import User
                user = User.query.get(user_id)
            except Exception as e:
                current_app.logger.error(e)
                return jsonify(errno=RET.DBERR, errmsg='数据库错误')
        g.user = user
        return f(*args,**kwargs)
    return inner




